<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>开发服务器运行方式 | 课程简介</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../C02-RouterAndBlueprint/index.html" />
    
    
    <link rel="prev" href="../C01-CreateProject/AboutParams.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="2.4"
        data-chapter-title="开发服务器运行方式"
        data-filepath="C01-CreateProject/StartDevelopmentServer.md"
        data-basepath=".."
        data-revision="Sat May 11 2019 20:06:35 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        课程简介
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="AboutFlask.html">
            
                
                    <a href="../AboutFlask.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        Flask介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2" data-path="C01-CreateProject/index.html">
            
                
                    <a href="../C01-CreateProject/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        工程搭建
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="C01-CreateProject/EnvInstall.html">
            
                
                    <a href="../C01-CreateProject/EnvInstall.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        环境安装
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="C01-CreateProject/HelloWorld.html">
            
                
                    <a href="../C01-CreateProject/HelloWorld.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        HelloWorld程序
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="C01-CreateProject/AboutParams.html">
            
                
                    <a href="../C01-CreateProject/AboutParams.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        参数说明
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="2.4" data-path="C01-CreateProject/StartDevelopmentServer.html">
            
                
                    <a href="../C01-CreateProject/StartDevelopmentServer.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        开发服务器运行方式
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="C02-RouterAndBlueprint/index.html">
            
                
                    <a href="../C02-RouterAndBlueprint/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        路由与蓝图
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="C02-RouterAndBlueprint/Router.html">
            
                
                    <a href="../C02-RouterAndBlueprint/Router.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        路由
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="C02-RouterAndBlueprint/Blueprint.html">
            
                
                    <a href="../C02-RouterAndBlueprint/Blueprint.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        蓝图
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="C03-RequestAndResponse/index.html">
            
                
                    <a href="../C03-RequestAndResponse/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        请求与响应
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="C03-RequestAndResponse/HandleRequest.html">
            
                
                    <a href="../C03-RequestAndResponse/HandleRequest.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        处理请求
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="C03-RequestAndResponse/HandleResponse.html">
            
                
                    <a href="../C03-RequestAndResponse/HandleResponse.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        处理响应
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="C03-RequestAndResponse/CookieAndSession.html">
            
                
                    <a href="../C03-RequestAndResponse/CookieAndSession.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        Cookie与Session
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="C04-HookAndContext/index.html">
            
                
                    <a href="../C04-HookAndContext/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        请求钩子与上下文
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="C04-HookAndContext/AbortAndErrorhandler.html">
            
                
                    <a href="../C04-HookAndContext/AbortAndErrorhandler.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        异常处理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="C04-HookAndContext/Hook.html">
            
                
                    <a href="../C04-HookAndContext/Hook.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        请求钩子
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="C04-HookAndContext/Context.html">
            
                
                    <a href="../C04-HookAndContext/Context.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        上下文
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="C05-Flask-RESTful/index.html">
            
                
                    <a href="../C05-Flask-RESTful/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        Flask-RESTful
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="C05-Flask-RESTful/QuickStart.html">
            
                
                    <a href="../C05-Flask-RESTful/QuickStart.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        起步
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="C05-Flask-RESTful/AboutView.html">
            
                
                    <a href="../C05-Flask-RESTful/AboutView.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        关于视图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="C05-Flask-RESTful/AboutRequest.html">
            
                
                    <a href="../C05-Flask-RESTful/AboutRequest.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        关于请求
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="C05-Flask-RESTful/AboutResponse.html">
            
                
                    <a href="../C05-Flask-RESTful/AboutResponse.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        关于响应
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >课程简介</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x5F00;&#x53D1;&#x670D;&#x52A1;&#x5668;&#x542F;&#x52A8;&#x65B9;&#x5F0F;">&#x5F00;&#x53D1;&#x670D;&#x52A1;&#x5668;&#x542F;&#x52A8;&#x65B9;&#x5F0F;</h1>
<p>&#x5728;1.0&#x7248;&#x672C;&#x4E4B;&#x540E;&#xFF0C;Flask&#x8C03;&#x6574;&#x4E86;&#x5F00;&#x53D1;&#x670D;&#x52A1;&#x5668;&#x7684;&#x542F;&#x52A8;&#x65B9;&#x5F0F;&#xFF0C;&#x7531;&#x4EE3;&#x7801;&#x7F16;&#x5199;<code>app.run()</code>&#x8BED;&#x53E5;&#x8C03;&#x6574;&#x4E3A;&#x547D;&#x4EE4;<code>flask run</code>&#x542F;&#x52A8;&#x3002;</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> flask <span class="hljs-keyword">import</span> Flask

app = Flask(__name__)

<span class="hljs-decorator">@app.route(&apos;/&apos;)</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">index</span><span class="hljs-params">()</span>:</span>
    <span class="hljs-keyword">return</span> <span class="hljs-string">&apos;Hello World&apos;</span>

<span class="hljs-comment"># &#x7A0B;&#x5E8F;&#x4E2D;&#x4E0D;&#x7528;&#x518D;&#x5199;app.run()</span>
</code></pre>
<h2 id="1-&#x7EC8;&#x7AEF;&#x542F;&#x52A8;">1 &#x7EC8;&#x7AEF;&#x542F;&#x52A8;</h2>
<pre><code class="lang-shell">$ export FLASK_APP=helloworld
$ flask run
 * Running on http://127.0.0.1:5000/
</code></pre>
<h3 id="&#x8BF4;&#x660E;">&#x8BF4;&#x660E;</h3>
<ul>
<li><p>&#x73AF;&#x5883;&#x53D8;&#x91CF; FLASK_APP &#x6307;&#x660E;flask&#x7684;&#x542F;&#x52A8;&#x5B9E;&#x4F8B;</p>
</li>
<li><p><code>flask run -h 0.0.0.0 -p 8000</code> &#x7ED1;&#x5B9A;&#x5730;&#x5740; &#x7AEF;&#x53E3;</p>
</li>
<li><p><code>flask run --help</code>&#x83B7;&#x53D6;&#x5E2E;&#x52A9;</p>
</li>
<li><p>&#x751F;&#x4EA7;&#x6A21;&#x5F0F;&#x4E0E;&#x5F00;&#x53D1;&#x6A21;&#x5F0F;&#x7684;&#x63A7;&#x5236;</p>
<p>&#x901A;&#x8FC7;<code>FLASK_ENV</code>&#x73AF;&#x5883;&#x53D8;&#x91CF;&#x6307;&#x660E;</p>
<ul>
<li><code>export FLASK_ENV=production</code> &#x8FD0;&#x884C;&#x5728;&#x751F;&#x4EA7;&#x6A21;&#x5F0F;&#xFF0C;&#x672A;&#x6307;&#x660E;&#x5219;&#x9ED8;&#x8BA4;&#x4E3A;&#x6B64;&#x65B9;&#x5F0F;</li>
<li><code>export FLASK_ENV=development</code>&#x8FD0;&#x884C;&#x5728;&#x5F00;&#x53D1;&#x6A21;&#x5F0F;</li>
</ul>
</li>
</ul>
<h3 id="&#x6269;&#x5C55;">&#x6269;&#x5C55;</h3>
<pre><code class="lang-shell">$ export FLASK_APP=helloworld
$ python -m flask run
 * Running on http://127.0.0.1:5000/
</code></pre>
<h2 id="2-pycharm&#x542F;&#x52A8;">2 Pycharm&#x542F;&#x52A8;</h2>
<p>&#x8BBE;&#x7F6E;&#x73AF;&#x5883;&#x53D8;&#x91CF;</p>
<p><img src="../images/pycharm&#x8FD0;&#x884C;&#x73AF;&#x5883;&#x53D8;&#x91CF;.png" alt="&#x8BBE;&#x7F6E;&#x73AF;&#x5883;&#x53D8;&#x91CF;"></p>
<p><img src="../images/pycharm&#x542F;&#x52A8;flask1.png" alt=""></p>
<h4 id="&#x65E7;&#x7248;&#x672C;pycharm&#x8BBE;&#x7F6E;">&#x65E7;&#x7248;&#x672C;Pycharm&#x8BBE;&#x7F6E;</h4>
<p><img src="../images/Pycharm&#x542F;&#x52A8;flask2.png" alt=""></p>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../C01-CreateProject/AboutParams.html" class="navigation navigation-prev " aria-label="Previous page: 参数说明"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../C02-RouterAndBlueprint/index.html" class="navigation navigation-next " aria-label="Next page: 路由与蓝图"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
